//
//  ViewController.m
//  KVC
//
//  Created by clz on 2019/7/21.
//  Copyright © 2019年 clz. All rights reserved.
//

#import "ViewController.h"
#import "Persion.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //kvc的目的是不通过属性，去赋值和取值
    Persion *persion = [[Persion alloc]init];
    
    //利用属性的set赋值
//    persion.name = @"xiaoMing";
    //get取值
    //    NSLog(@"persion.name = %@",persion.name);

    //利用KVC
    //赋值
    [persion setValue:@"xiaoMing" forKey:@"name"];
    //取值
//    NSLog(@"persion.name2 = %@",[persion valueForKey:@"name"]);
    
    Address *address = [[Address alloc]init];
//    [address setValue:@"wuxi" forKey:@"city"];
//    persion.address = address;
    [persion setValue:address forKey:@"address"];
    
    //多级访问（访问persion里面的address里面的city） //多级访问一定是keypath
    [persion setValue:@"wuxi" forKeyPath:@"address.city"];
    
//    NSLog(@"city = %@",persion.address.city);//属性get方法访问
    NSLog(@"city01 = %@",[persion valueForKeyPath:@"address.city"]);
    
    
    
}


@end
